import java.util.concurrent.atomic.AtomicLong;

public class AtomicLongTest {
    public static AtomicLong largest = new AtomicLong();

    public static void main(String[] args) {
        long oldValue;
        long newValue;
        long observed = 1;
        do {
            oldValue = largest.get();
            newValue = Math.max(oldValue, observed);
            System.out.printf("oldValue: %d, newValue: %d, observed: %d%n", oldValue, newValue, observed);
        } while (!largest.compareAndSet(oldValue, newValue));
    }
}
